<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise</title>
</head>
<body>
    <script type="module">
        // const MyPromise = require('./MyPromise.js');
        // 直接在 H5 中使用 import 会有问题
        // 可以在项目里试，或者安装 Live Serve 来跑 .html
        import MyPromise from './MyPromise.js'

        // 测试
        const promise = new MyPromise((resolve, reject) => {
            // resolve('success'); // resolve success
            // reject('err'); // reject err
            setTimeout(() => {
                resolve('timeout'); // 3s 后输出 resolve timeout
            }, 3000);
        });

        // promise.then(function (value) {
        //     console.log('resolve', value);
        // }, function (reason) {
        //     console.log('reject', reason);
        // });

        // 用箭头函数方法
        // promise.then(value => {
        //     console.log('resolve', value);
        // }, reason => {
        //     console.log('reject', reason);
        // });

        // // 多次调用
        // promise.then(value => {
        //     console.log('1');
        //     console.log('resolve', value);
        // });

        // promise.then(value => {
        //     console.log('2');
        //     console.log('resolve', value);
        // });

        // promise.then(value => {
        //     console.log('3');
        //     console.log('resolve', value);
        // });

        // 连续调用
        promise.then(value => {
            console.log('lianxu1');
            console.log('resolve');
        }).then(value => {
            console.log('lianxu2');
            console.log('resolve');
        });
    </script>
</body>
</html>